package com.example.osixaffairssystem.service.impl;

import com.example.osixaffairssystem.domain.PageBean;
import com.example.osixaffairssystem.domain.model.Emp;
import com.example.osixaffairssystem.mapper.EmpMapper;
import com.example.osixaffairssystem.service.EmpService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
@RequiredArgsConstructor
public class EmpServiceImpl implements EmpService {

    final EmpMapper empMapper;

    @Override
    public List<Emp> list() {
        return empMapper.list();
    }

    @Override
    public PageBean<Emp> listToPage(Integer page, Integer pageSize) {
        PageHelper.startPage(page, pageSize);

        Page<Emp> p = (Page<Emp>) empMapper.list();

        return new PageBean<>(p.getTotal(), p.getResult());
    }

    @Override
    public Integer insert(Emp emp) {
        empMapper.insert(emp);
        return emp.getId();
    }

    @Override
    public void update(Emp emp) {
        empMapper.update(emp);
    }

    @Override
    public void delete(List<Integer> ids) {
        empMapper.delete(ids);
    }


}
